const router = require('koa-router')();
const User = require('../models/user');


router.post('/api', (ctx, next) => {
    ctx.body = {
        msg: '这是受保护的资源'
    }
});

router.post('/api/getUser', async (ctx, next) => {
    const res = {};
    try {
        const user = await User.findAll();
        const data = user || [];
        res.code = 0;
        res.message = 'success';
        res.data = data;
    } catch(e) {
        res.code = 1;
        res.message = '查询失败';
    }
    ctx.body = res
});

module.exports = router;
